package com.zhouyu.aop.config;

import com.zhouyu.aop.advice.ZhouyuBeforeAdvice;
import com.zhouyu.aop.service.OrderService;
import com.zhouyu.service.UserService;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author mimao funfind@yeah.net
 * @date ${{
 */
@Configuration
@ComponentScan("com.zhouyu")
public class AppConfig {

//	@Bean
//	public ProxyFactoryBean OrderService(){
//
//		OrderService orderService = new OrderService();
//
//		ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
//		proxyFactoryBean.addAdvice(new ZhouyuBeforeAdvice());
//		proxyFactoryBean.setTarget(orderService);
//		return proxyFactoryBean;
//	}

	// beanPostProcess
	@Bean
	public BeanNameAutoProxyCreator beanNameAutoProxyCreator(){

		BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator();
		beanNameAutoProxyCreator.setBeanNames("orderS*");   //ProxyFactory
		beanNameAutoProxyCreator.setInterceptorNames("zhouyuBeforeAdvice");
		return beanNameAutoProxyCreator;
	}
}
